<script type="text/javascript" >
    jQuery(document).ready(function(){
        jQuery('.stExtra').remove();
    });
    stFacebookToolbox.load_tooltip();
    stFacebookToolboxcustom.on_submitform_new('#template_upload');
    stFacebookToolbox.loadUploadButton('200');
    stFacebookToolbox.loadRemoveButton();
    stFacebookToolbox.shortAction();
    stFacebookToolbox.sortColumn();
        jQuery("a[rel^='prettyPhoto']").prettyPhoto({
            theme:'facebook',
            default_height:100,
            keyboard_shortcuts: false
        });
    function add_image(){
        jQuery('.upload_field').slideDown();
        jQuery("#id").val('');
        jQuery("#name").val('');
        jQuery("#calculation").val('');
        
    }
    function edit(id,name,calculation){
        jQuery('.upload_field').slideDown();
        jQuery("#id").val(id);
        jQuery("#name").val(name);
        jQuery("#calculation").val(calculation);
    }
</script>
<style>
th.column-CouponTemplateID {
    width:40px;
}
</style>

<div class="w100p bgl">
    <div class="w100p bgr p5b">
        <ul class="postcardAction" style="margin-left: 10px;padding-top: 15px;">
                
              <li>
                    <a onclick="window.open('<?php echo get_bloginfo('url');?>/coupon/sales');" class="button add-new-h2 anchor">
                        Coupon Registering
                    </a>
                </li>
            </ul>
  
<table class="widefat" cellspacing="0">
                <thead>
                    <tr>
                        <?php print_column_headers('stFacebookToolbox_stFacebookToolbox'); ?>
                    </tr>
                </thead>

                <tbody>
                <?php
                if (count($results) > 0) {
                    
                    $tr_class = "";
                    $upload_data = wp_upload_dir();
                    foreach ($results as $result) {
                        if($result->status == 1){
                            $status = 'Deactivate';
                            $style = '';
                            $background = 'style="background-color:#FFF7C0;"';
                            $onclick = '';
                        }
                        else {
                            $status = 'Activate';
                            $background = '';
                            $style = 'style="cursor:pointer;"';
                            $com = "Are you sure you want to activate this campaign? ";
                            if($active != ''){
                                $com .= 'This will deactivate the campaign \"'.$active.'\"';
                            }
                            echo "<script type='text/javascript'>
                                    var data$result->CouponTemplateID = new Array();
                                    data$result->CouponTemplateID['active'] = $result->CouponTemplateID;
                                    //alert('$result->CouponTemplateID');
                                  </script>
                                ";
                            $onclick = "onclick='stFacebookToolbox.confirmModal(\" $com\", \"active\",data$result->CouponTemplateID);'";
//                            $onclick = "onclick='alert(data$result->CouponTemplateID[\"active\"]);'";
                        }
                        $array = explode('-',substr($result->ValidFromDateTime,0,10));
                        $from = $array[2].'.'.$array[1].'.'.$array[0];
                        $array = explode('-',substr($result->ValidToDateTime,0,10));
                        $to = $array[2].'.'.$array[1].'.'.$array[0];
                        if($user_id == 14){
                            $from = str_replace('-','.',$result->CouponTemplateName);
                            $to = '30.01.2011';
                        }
                        $description  = (strlen($result->CouponTemplateDescription) > 35)?substr($result->CouponTemplateDescription,0,35).'...':$result->CouponTemplateDescription;
                        if( empty($tr_class) || $tr_class == "class='bg_gray2'"){
                            $tr_class = "class='bg_gray1'";
                        }else{
                            $tr_class = "class='bg_gray2'";
                        }
                        echo "<tr id='$result->CouponTemplateID' $tr_class $background>"
                        . "<td>" . $result->CouponTemplateID. "</td>"
                        . "<td>" . $result->CouponTemplateName
                        . "<div class=\"row-actions short_action\">";
                        if($result->status != 1)    
                            echo "<div $onclick style='cursor:pointer;'>Activate | </div>";
                        
                        echo "<div onclick='stFacebookToolbox.redirect(\"".get_bloginfo('url')."/wp-admin/admin.php?page=stFacebookToolbox&action=edit_coupon_template&id=$result->CouponTemplateID\")' style='cursor:pointer;'>Edit | </div>"
                        . "<span class='trash' short_action='delete' id='$result->CouponTemplateID' confirm='Are you sure you want to delete this campaign?' style='cursor:pointer;margin-left:3px;'> Trash </span>"
                        . "</div>"
                        . "</td>"
                        . "<td><a rel='prettyPhoto' href='{$model->getFull($result->CouponTemplateGraphicsID)}' title=''><img src='{$model->getgraphic($result->CouponTemplateGraphicsID)}' title='' width=70 /></a>"
                        . "</td>"
                        . "<td>".$from
                        . "</td>"
                        . "<td>".$to
                        . "</td>"
                        . "<td>{$model->getdiscount($result->DiscountTypeID)}"
                        . "</td>"
                        . "<td>{$result->DiscountValue}"
                        . "</td>"
                        . "</tr>"
                        ;
                    }
                }
                ?>
                </tbody>
            </table>
            <div class="page_d">
                <?php echo $pagination?>
                <div class="cl"></div>
            </div>
    </div>
</div>